#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
int isLeapYear(int y)
{
    if ((y % 4 == 0 && y % 100 != 0) || y % 400 == 0)
        return 1;
    return 0;
}


int merge(int a, int b)
{
    a = (a % 10) * 10 + a / 10;
    b = (b % 10) * 10 + b / 10;
    return b * 100 + a;
}

float piecewise(float x)
{
    if (x > 0)
        return x / 2 + 1;
    else if (x == 0)
        return 1;
    else
        return -2 * x - 1;
}



int MaxDayMonth(int year, int month)
{
    if (isLeapYear(year) && month == 2)
        return 29;

    switch (month)
    {
    case 1:
        return 31;
    case 2:
        return 28;
    case 3:
        return 31;
    case 4:
        return 30;
    case 5:
        return 31;
    case 6:
        return 30;
    case 7:
        return 31;
    case 8:
        return 31;
    case 9:
        return 30;
    case 10:
        return 31;
    case 11:
        return 30;
    case 12:
        return 31;
    default:
        return 0;
    }
}

int integersum(int n)
{
    int cnt = 6;
    int sum = 0;
    while (cnt && n)
    {
        if (n % 7 == 0 || n % 11 == 0)
        {

            cnt--;
            sum += n;
        }
        n--;
    }
    return sum;
}

int sum_prime(int a, int b)
{
    if (a > b)
    {
        int c = a;
        a = b;
        b = c;
    }
    int* prime = (int*)calloc(b + 1, sizeof(int));
    prime[0] = 0;
    prime[1] = 0;
    for (int i = 2; i < b + 1; i++)
    {
        prime[i] = 1;
    }
    for (int i = 2; i < b + 1; i++)
    {
        if (prime[i])
        {
            for (int j = 2; j * i < b + 1; j++)
                prime[j * i] = 0;
        }
    }

    int sum = 0;
    for (int i = a; i < b; i++)
    {
        if (prime[i])
            sum += i;
    }
    free(prime);
    return sum;
}


double sequence(int n)
{
    double sum = 1;
    double num = 1;
    for (int i = 1; i < n; i++)
    {
        num = 1.0 / (num + 5);
        sum += num;
    }
    return sum;
}


double polynomial(int n)
{
    double num = 0;
    int k = 0;
    double sum = 0;
    for (int i = 1; i <= n; i++)
    {
        k += i;
        num = 1.0 / k;
        sum += num;
    }
    return sum;
}

double polynomial(int n)
{
    int q = 1;
    double ret = 0;
    for (int i = 1; i <= n; i++)
    {
        double num = 1.0 / (i * i) * q;
        q *= -1;
        ret += num;
    }
    return ret;
}

int coprime(int a, int b)
{
    int min = a;
    if (min > b)
        min = b;
    for (int i = 2; i < min; i++)
    {
        if (a % i == 0 && b % i == 0)
            return 0;
    }
    return 1;
}